﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using xml_classes;

namespace QuestPrototype
{
    class Drawing
    {
        public static void DrawLine(SpriteBatch sprBatch, Texture2D spr, Vector2 a, Vector2 b, Color col)
        {
            Vector2 Origin = new Vector2(0.5f, 0.0f);
            Vector2 diff = b - a;
            float angle;
            Vector2 Scale = new Vector2(1.0f, diff.Length() / spr.Height);

            angle = (float)(Math.Atan2(diff.Y, diff.X)) - MathHelper.PiOver2;

            sprBatch.Draw(spr, a, null, col, angle, Origin, Scale, SpriteEffects.None, 1.0f);
        }

        public static void DrawPolygon(Polygon pol, SpriteBatch sprBatch, Texture2D spr, Color col, bool fill)
        {
            List<Vector2> vertices = pol.getVertices();
            if (vertices.Count < 2)
            {
                return;
            }
            for (int i = 0; i < vertices.Count - 1; i++)
            {
                DrawLine(sprBatch, spr, vertices[i], vertices[i + 1], col);
            }
            if (vertices.Count > 2)
            {
                DrawLine(sprBatch, spr, vertices[0], vertices[vertices.Count - 1], col);
            }
        }

    }
}
